<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/4/6 12:27
 */

namespace App\Dao\Users;


use App\Dao\BaseDao;
use App\Model\Users\UserMessages;

class UserMessagesDao extends BaseDao
{


    public function getInfoByPk(int $messageId)
    {
        return UserMessages::query()->where('id','=',$messageId)->first();
    }

    public function getUniApplyIdAndUid(int $applyId,int $toUid)
    {
        return UserMessages::query()->where('apply_uid','=',$applyId)->where('to_uid','=',$toUid)->first();
    }


    /**
     * 获取我的消息
     * @param int $uid
     * @param int $limit
     * @return UserMessages[]|\Hyperf\Database\Model\Builder[]|\Hyperf\Database\Model\Collection
     */
    public function getMyMessages(int $uid,int $offsetId = 0,int $limit = 10)
    {
        $query =  UserMessages::with('sendUser')
            ->where('to_uid','=',$uid);

        if(!empty($offsetId))
        {
            $query->where('id','<',$offsetId);
        }
        $query->orderBy('id','desc')->limit($limit);

        return $query->get();
    }

}